home *** CD-ROM | disk | FTP | other *** search
- Path: vixen.cso.uiuc.edu!usenet
- From: Dragos-Anton Manolescu <manolesc@uiuc.edu>
- Newsgroups: comp.lang.c++
- Subject: HELP: STL adaptor problem (find_if + bind2nd)
- Date: 12 Apr 1996 16:11:26 -0500
- Organization: University of Illinois at Urbana-Champaign
- Message-ID: <opg2a9p2pt.fsf@sweetbay.will.uiuc.edu>
- Reply-To: Dragos Manolescu <manolesc@uiuc.edu>
- NNTP-Posting-Host: sweetbay.will.uiuc.edu
- X-Newsreader: Gnus v5.1
-
-
- Hello,
-
- I'm trying to find an element in a vector and I ran into problems
- usign the bind2nd function adaptor. If I define the function as a
- binary function object, everything works fine:
-
- struct MatchFirst : binary_function<Range,int,bool> {
- bool operator() (const Range& a,const int& b) const
- {
- return a.r.first == b;
- }
- } matchFirst;
-
- and the call is:
-
- where = find_if(v.begin(),
- v.end(),
- bind2nd(matchFirst,i));
-
- However, I tried to make the function object part of the class that it
- is supposed to work with (i.e. Range):
-
- class Range {
- public:
- ...
- class MatchFirst {
- public:
- bool operator()(Range&,int&) const;
- };
- ...
- };
-
- bool Range::MatchFirst::operator()(Range& a,int& b) const
- {
- return a.r.first == b;
- }
-
- with a call like this:
-
- where = find_if(v.begin(),
- v.end(),
- bind2nd(Range::MatchFirst(),i));
-
- This time it fails to compile:
-
- g++ -g -Wall -c stltest.C -o stltest.o
- /usr/include/g++/function.h:193: `first_argument_type' is not a member of type `Range::MatchFirst'
- /usr/include/g++/function.h:194: `result_type' is not a member of type `Range::MatchFirst'
- /usr/include/g++/function.h:194: type/value mismatch in template parameter list for `template <class Arg, class Result> class unary_function'
- /usr/include/g++/function.h:194: type/value mismatch in template parameter list for `template <class Arg, class Result> class unary_function'
- /usr/include/g++/function.h:197: syntax error before `;'
- /usr/include/g++/function.h:200: confused by earlier errors, bailing out
- make: *** [stltest.o] Error 1
- make: Target `all' not remade because of errors.
-
-
- What am I doing wrong here? Please reply by e-mail if possible.
-
- Thank you,
- --
- dam http://www.uiuc.edu/ph/www/manolesc
-